home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.multimedia;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Vector;
-
- public class ImageMap extends ImageViewer {
- protected Vector rects;
- private int rectCount;
- private boolean showrect;
- private ImageMapRect lastrect;
-
- public ImageMap() {
- this(true);
- }
-
- public ImageMap(boolean var1) {
- this.rectCount = 0;
- this.rects = new Vector();
- this.showrect = var1;
- }
-
- public ImageMap(boolean var1, String var2) throws MalformedURLException {
- this(var1, new URL(var2));
- }
-
- public ImageMap(boolean var1, URL var2) throws MalformedURLException {
- this(var1, Toolkit.getDefaultToolkit().getImage(var2));
- }
-
- public ImageMap(boolean var1, Image var2) throws MalformedURLException {
- super(var2);
- this.rectCount = 0;
- this.rects = new Vector();
- this.showrect = var1;
- }
-
- public void setShowrect(boolean var1) {
- this.showrect = var1;
- }
-
- public boolean getShowrect() {
- return this.showrect;
- }
-
- public boolean addRect(int var1, int var2, int var3, int var4) {
- ImageMapRect var5 = new ImageMapRect(var1, var2, var3, var4);
- if (!this.overlap(var5)) {
- var5.visible = false;
- this.rects.addElement(var5);
- ++this.rectCount;
- return true;
- } else {
- return false;
- }
- }
-
- public boolean addRect(ImageMapRect var1) {
- if (!this.overlap(var1)) {
- var1.visible = false;
- this.rects.addElement(var1);
- ++this.rectCount;
- return true;
- } else {
- return false;
- }
- }
-
- public ImageMapRect findRect(int var1, int var2) {
- Object var4 = null;
-
- for(int var3 = 0; var3 < this.rects.size(); ++var3) {
- ImageMapRect var5 = (ImageMapRect)this.rects.elementAt(var3);
- if (((Rectangle)var5).inside(var1, var2)) {
- return var5;
- }
- }
-
- return null;
- }
-
- public boolean overlap(ImageMapRect var1) {
- byte var2 = 0;
- if (var2 >= this.rects.size()) {
- return false;
- } else {
- ImageMapRect var3 = (ImageMapRect)this.rects.elementAt(var2);
- return ((Rectangle)var1).intersects(var3);
- }
- }
-
- public boolean mouseMove(Event var1, int var2, int var3) {
- if (this.showrect) {
- ImageMapRect var4 = this.findRect(var2, var3);
- if (var4 != null && !var4.visible) {
- Graphics var6 = ((Component)this).getGraphics();
- var6.setXORMode(Color.red);
- var6.drawRect(var4.x, var4.y, var4.width, var4.height);
- var4.visible = true;
- this.lastrect = var4;
- return true;
- }
-
- if (this.lastrect != null && var4 == null && this.lastrect.visible) {
- Graphics var5 = ((Component)this).getGraphics();
- var5.setXORMode(Color.red);
- var5.drawRect(this.lastrect.x, this.lastrect.y, this.lastrect.width, this.lastrect.height);
- this.lastrect.visible = false;
- return true;
- }
- }
-
- return super.mouseMove(var1, var2, var3);
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- ImageMapRect var4 = this.findRect(var2, var3);
- if (var4 == null) {
- return super.mouseDown(var1, var2, var3);
- } else {
- this.lastrect = var4;
- return true;
- }
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- ImageMapRect var4 = this.findRect(var2, var3);
- if (var4 != null && var4 == this.lastrect) {
- Event var5 = new Event(var4, 1001, (Object)null);
- ((Component)this).postEvent(var5);
- return true;
- } else {
- return super.mouseUp(var1, var2, var3);
- }
- }
- }
-